package com.standard.logcat.interceptor

import android.os.Handler
import android.os.Looper
import com.standard.logcat.entity.LogcatItem
import com.standard.logcat.logBus.LogBus
import com.standard.logcat.provider.Init
import okhttp3.internal.platform.Platform
import okhttp3.logging.HttpLoggingInterceptor

class Logcat : HttpLoggingInterceptor.Logger {
    private val handler = Handler(Looper.myLooper()!!)

    override fun log(message: String) {
        Platform.get().log(message)

        handler.post {
            if (message.isNotEmpty())
                LogBus.log.value = LogcatItem(message)
        }
    }
}